package com.online.shopping.common.utils;

import com.online.shopping.pojo.TbSeller;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

// 建议该类不放到pojo包中
public class UserDetailImpl implements UserDetails {

	private TbSeller tbSeller;

	private Collection<? extends GrantedAuthority> authorities;

	public UserDetailImpl() {}

	public UserDetailImpl(TbSeller tbSeller, Collection<? extends GrantedAuthority> authorities) {
		this.tbSeller = tbSeller;
		this.authorities = authorities;
	}

	// 获取权限列表
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return this.authorities;
	}

	@Override
	public String getPassword() {
		return this.tbSeller.getPassword();
	}

	@Override
	public String getUsername() {
		return this.tbSeller.getSellerId();
	}

	// 判断账号是否过期
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	// 判断账号是否锁定
	@Override
	public boolean isAccountNonLocked() {
		return this.tbSeller.getStatus().equals("1");
	}

	// 判断密码是否过期
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	// 判断用户是否可用
	@Override
	public boolean isEnabled() {
		return true;
	}
}
